package cn.edu.lingnan.fruitshop.controller;


import cn.edu.lingnan.fruitshop.common.JSONResult;
import cn.edu.lingnan.fruitshop.service.CarttableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张小凡
 * @since 2022-01-04
 */
@Controller
@RequestMapping("/carttable")
public class CarttableController {

    @Autowired
    private CarttableService carttableService;

    //加入购物车
    @GetMapping("/cartInfo")
    @ResponseBody
    public JSONResult<Void> cartInfo(HttpSession session,Integer goodId,Integer num){
        return carttableService.cartInfo(session, goodId, num);
    }

    //查看我的购物车信息
    @GetMapping("/myCart")
    public String myCart(HttpSession session,Model model){
        return carttableService.myCart(session, model);
    }

    //删除一条购物车记录
    @GetMapping("/deleteOneCart")
    public String deleteOneCart(Integer cartId){
        return carttableService.deleteOneCart(cartId);
    }

}

